package com.thread.example.config;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author guoQ.z
 * @date 2021/1/27 18:17
 * TODO
 */
public class MyThreadFactory implements ThreadFactory {

    private final String threadPrefix;
    private final AtomicInteger atomicInteger = new AtomicInteger(1);

    public MyThreadFactory(String threadPrefix) {
        this.threadPrefix = threadPrefix;
    }

    @Override
    public Thread newThread(Runnable r) {
        return new Thread(r, threadPrefix + atomicInteger.getAndIncrement());
    }
}
